//
//  LoginTableViewController.m
//  BakeCenter
//
//  Created by Barnett Wu on 15/9/23.
//  Copyright (c) 2015年 Baked. All rights reserved.
//

#import "LoginTableViewController.h"
#import "LoginCell.h"
#import "LoginHeaderView.h"

@interface LoginTableViewController ()

@end

@implementation LoginTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerClass:[LoginCell class] forCellReuseIdentifier:@"loginCell"];
    [self setUpNavigationBar];
    
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(recycleKeyboard:)];
    
    [self.tableView addGestureRecognizer:tapGR];
}

- (void)recycleKeyboard:(UITapGestureRecognizer *)tapGR
{
    for (int i = 0 ; i < 6 ; i ++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        LoginCell *cell = (LoginCell *)[self.tableView cellForRowAtIndexPath:indexPath];
        [cell.inputTextField resignFirstResponder];
    }
}


#pragma mark - headerView
- (void)setUpHeaderView
{

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 180;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    LoginHeaderView *headerView = [[LoginHeaderView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    [self setUpHeaderView];
    
    return headerView;
}

#pragma mark - Navigation push and pull

- (void)setUpNavigationBar
{
    self.navigationItem.title = @"Login";
    UIBarButtonItem *returnButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Entypo_LoginReturn_64"] style:(UIBarButtonItemStylePlain) target:self action:@selector(returnMain:)];
    UIBarButtonItem *registerButton = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(presentRegisterView:)];
    
    self.navigationItem.leftBarButtonItem = returnButton;
    self.navigationItem.rightBarButtonItem = registerButton;
    
}

- (void)returnMain:(UIBarButtonItem *)barButton
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)presentRegisterView:(UIBarButtonItem *)barButton
{
    RegisterViewController *registerTVC = [[RegisterViewController alloc] init];
    [self.navigationController setAnimationWithSubtype:0 andAnimationType:9];
    [self.navigationController pushViewController:registerTVC animated:YES];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 51;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifier = @"loginCell";
    LoginCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor babyBlueColor];
    NSArray *titleArr = @[@"用户名",@"密码",@"确认密码",@"手机号码",@"邮箱"];
    cell.titleLabel.text = titleArr[indexPath.row];
    
    return cell;
}


#pragma mark - selectAtIndexPath

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (int i = 0 ; i < 6 ; i ++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        LoginCell *cell = (LoginCell *)[self.tableView cellForRowAtIndexPath:indexPath];
        [cell.inputTextField resignFirstResponder];
    }
    
}






@end
